<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="编号" prop="serialnumber">
      <el-input v-model="dataForm.serialnumber" placeholder="编号"></el-input>
    </el-form-item>
    <el-form-item label="名称" prop="nursingname">
      <el-input v-model="dataForm.nursingname" placeholder="名称"></el-input>
    </el-form-item>
    <el-form-item label="价格" prop="serviceprice">
      <el-input v-model="dataForm.serviceprice" placeholder="价格"></el-input>
    </el-form-item>
    <el-form-item label=" 描述" prop="message">
      <el-input v-model="dataForm.message" placeholder=" 描述"></el-input>
    </el-form-item>
    <el-form-item label="状态" prop="status">
      <!-- <el-input v-model="dataForm.status" placeholder="状态"></el-input> -->
       <el-radio-group v-model="dataForm.status" size="small" >
        <el-radio-button :label="1">启用</el-radio-button>
        <el-radio-button :label="2" >禁用</el-radio-button>
     </el-radio-group>
    </el-form-item>
    <el-form-item label="执行周期" prop="executioncycle">
      <el-input v-model="dataForm.executioncycle" placeholder="执行周期"></el-input>
    </el-form-item>
    <el-form-item label="执行次数" prop="executiontimes">
      <el-input v-model="dataForm.executiontimes" placeholder="执行次数"></el-input>
    </el-form-item>
    
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          serialnumber: '',
          nursingname: '',
          serviceprice: '',
          message: '',
          status: '',
          executioncycle: '',
          executiontimes: '',
          isdeleted: ''
        },
        dataRule: {
          serialnumber: [
            { required: true, message: '编号不能为空', trigger: 'blur' }
          ],
          nursingname: [
            { required: true, message: '名称不能为空', trigger: 'blur' }
          ],
          serviceprice: [
            { required: true, message: '价格不能为空', trigger: 'blur' }
          ],
          message: [
            { required: true, message: ' 描述不能为空', trigger: 'blur' }
          ],
          status: [
            { required: true, message: '状态 1：启用；2：停用不能为空', trigger: 'blur' }
          ],
          executioncycle: [
            { required: true, message: '执行周期不能为空', trigger: 'blur' }
          ],
          executiontimes: [
            { required: true, message: '执行次数不能为空', trigger: 'blur' }
          ],
          isdeleted: [
            { required: true, message: '逻辑删除标记（0：显示；1：隐藏）不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/nursecontent/nursecontent/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.serialnumber = data.nurseContent.serialnumber
                this.dataForm.nursingname = data.nurseContent.nursingname
                this.dataForm.serviceprice = data.nurseContent.serviceprice
                this.dataForm.message = data.nurseContent.message
                this.dataForm.status = data.nurseContent.status
                this.dataForm.executioncycle = data.nurseContent.executioncycle
                this.dataForm.executiontimes = data.nurseContent.executiontimes
                this.dataForm.isdeleted = data.nurseContent.isdeleted
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/nursecontent/nursecontent/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'serialnumber': this.dataForm.serialnumber,
                'nursingname': this.dataForm.nursingname,
                'serviceprice': this.dataForm.serviceprice,
                'message': this.dataForm.message,
                'status': this.dataForm.status,
                'executioncycle': this.dataForm.executioncycle,
                'executiontimes': this.dataForm.executiontimes,
                'isdeleted': this.dataForm.isdeleted
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
